<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp"/>
  <link rel="alternate icon" type="image/png" href="assets/i/favicon.png">
  <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
  <title>商品展示</title>
</head>
<body>
<header class="am-topbar am-topbar-fixed-top">
  <div class="am-container">
    <h1 class="am-topbar-brand">
      <a href="#">Shopping</a>
    </h1>

    <button class="am-topbar-btn am-topbar-toggle am-btn am-btn-sm am-btn-secondary am-show-sm-only"
            data-am-collapse="{target: '#collapse-head'}"><span class="am-sr-only">导航切换</span> <span
        class="am-icon-bars"></span></button>

    <div class="am-collapse am-topbar-collapse" id="collapse-head">
      <ul class="am-nav am-nav-pills am-topbar-nav">
        <li ><a href="index.jsp">首页</a></li>
        <li class="am-active"><a href="productshow.jsp">商品展示</a></li>
        <li ><a href="MyShoppingCar.jsp">我的购物车</a></li>
        <li><a href="MyOrderForm.jsp">我的订单</a></li>
        <li><a href="#">联系我们</a></li>
        </li>
      </ul>
	<%
		if(session.getAttribute("user") == null) {
	%>
	<div class="am-topbar-right">
        <button class="am-btn am-btn-secondary am-topbar-btn am-btn-sm" onclick="location.href='regin.jsp';"><span class="am-icon-pencil" ></span> 注册</button>
      </div>

      <div class="am-topbar-right">
        <button class="am-btn am-btn-primary am-topbar-btn am-btn-sm"onclick="location.href='login.jsp';"><span class="am-icon-user"></span> 登录</button>
      </div>
	<%
		} else {
			%>
			<div class="am-topbar-right">
			 
			 <button class="am-btn am-btn-primary am-topbar-btn am-btn-sm"onclick="location.href='login.jsp';"><span class="am-icon-user"></span> 个人中心</button>
			<%
		}
	%>
     
  </div>
  
  </div>
  
</header>
<div align="right">
  <input type="email" id="doc-ipt-3" placeholder="搜索">
 <button class="am-btn am-btn-primary am-btn-xs">搜索</button>
    </div>

<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.js"></script>
<script src="assets/js/handlebars.min.js"></script>
<script src="assets/js/amazeui.widgets.helper.js"></script>
<div class="am-scrollable-horizontal">
<table class="am-table  am-table-striped am-text-nowrap">
    <tbody>
        <tr>
            <td>品牌：</td>
            <td><a href="#">大宝</a></td>
            <td><a href="#">欧莱雅</a></td>
            <td><a href="#">玉兰油</a></td>
           <td> <a href="#">Kans/韩束</a></td>
           <td> <a href="#">雅诗兰黛</a></td>
           <td><a href="#">欧莱雅</a></td>
            
        </tr>
        <tr>
            <td>化妆品类型：</td>
            <td><a href="#">补水保湿</a></td>
            <td><a href="#">去黄气</a></td>
            <td><a href="#">美白</a></td>
           <td> <a href="#">滋润</a></td>  
           <td> <a href="#">护肤</a></td>
        </tr>
        <tr>
            <td>产地：</td>
            <td><a href="#">中国</a></td>
            <td><a href="#">美国</a></td>
            <td><a href="#">俄国</a></td>
           <td> <a href="#">日本</a></td>
        </tr>
        
    </tbody>
</table>
      </div>
      <table border="1" spacing="2">
<%!
	public static final String DRIVER = "com.mysql.jdbc.Driver";
	public static final String USER = "root";
	public static final String PASS = "wzly0129";
	public static final String URL = "jdbc:mysql://localhost:3306/test";
	public static final int PAGESIZE = 5;
	int w=0; 
	int pageCount;
	int curPage = 10;
	StringBuffer str= new StringBuffer();
	
%>
<%
	if (curPage<=0){
		curPage=1;
	}
	//一页放5个
	String user = null;
	String pass = null;
	try{
		Class.forName(DRIVER);
		Connection con = DriverManager.getConnection(URL,USER,PASS);
		String sql = "SELECT * FROM product";
		PreparedStatement stat = con.prepareStatement(sql,ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY);
		ResultSet rs = stat.executeQuery();
		rs.last();
		int size = rs.getRow();
		
		pageCount = (size%PAGESIZE==0)?(size/PAGESIZE):(size/PAGESIZE+1);
		String tmp = request.getParameter("curPage");
		
		if(tmp==null){
			tmp="1";
		}
		curPage = Integer.parseInt(tmp);
		if(curPage>=pageCount) curPage = pageCount;
		boolean flag = rs.absolute((curPage-1)*PAGESIZE+1);
		//out.println(curPage);
		int count = 0;
		
		%>
<form method="post" action="">
  <table class="am-table am-table-bordered am-table-striped am-text-nowrap">
		<thead>
        <tr>
            <th>商品名称</th>
            <th>品牌</th>
            <th>产地</th>
            <th>价格</th>
            <th>    </th>
        </tr>
    </thead>
    <% 
		do{
			if(count>=PAGESIZE)break;
			String pname = rs.getString("pname");
			String pdesign = rs.getString("pdesign");
			String pcountry= rs.getString("pcountry");
			String price = rs.getString("price");
			count++;
			w++;
			%>
			<td>
			<div class="am-form-group">
      <label class="am-checkbox-inline">
        <input type="checkbox" value="<%=pname+"    "+pdesign+"     "+price%>" name="choice"><%=pname%>
        
      </label>
    </div>
</td>
			<td><%=pdesign %></td>
			<td><%=pcountry %></td>
			<td><%=price %></td>		
			<tr>
			<%
		}while(rs.next());
		con.close();
	}
	catch(Exception e){
		out.print("shibai");
	}
	
%>
<%  
request.setCharacterEncoding("utf-8");
String[] good=request.getParameterValues("choice");
	if (good!=null){
		for (int k=0;k<good.length;k++){
			str.append(good[k]+"<br>");
		}
		session.setAttribute("book", str);
		String s= new String(str);
		StringBuffer messg = (StringBuffer)session.getAttribute("book");
	
	}

%>
  </table>
<div align="right">

<input type='hidden' name='cars' value=<%=str %>>
<input type="submit" class="am-btn am-btn-warning" value="加入购物车">
</div>
</form>
</table>
</form>


<div class="am-pagination am-pagination-centered">
<%if (curPage<=0){
	curPage=1;
} %>
  <li ><a href="productshow.jsp?curPage=<%=curPage-1%>">&laquo;</a></li>
  <%for(int i=1;i<=pageCount;i++){ %>
  <%if (curPage==i) {%>
  <li class="am-active">
  <%} else{%>
  <li> 
  <% }%>
  <a href="productshow.jsp?curPage=<%=i%>"><%=i%></a>
  </li>
  <%} %>
  <li><a href="productshow.jsp?curPage=<%=curPage+1%>">&raquo;</a></li>
</div>  

</body>


</html>